#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QAction>
#include <QMenu>
#include <QToolButton>


#include "custommenubutton.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->splitter->setSizes({100, 600});


    // 创建前两个按钮并使用垂直布局
    QToolButton *button1 = new QToolButton(ui->tab);
    // 创建一个QAction
    QAction *action = new QAction(QIcon(":/res/brush_fill.png"), "Click Me", button1);
    action->setShortcut(QKeySequence::Save);
    action->setStatusTip("Save the document");

    // 将QAction添加到QToolButton中
    button1->setDefaultAction(action);

    QToolButton *button2 = new QToolButton(ui->tab);
    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addWidget(button1);
    leftLayout->addWidget(button2);
    // 设置按钮的自适应大小
    // button1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    // button2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    button1->setFixedSize(QSize(80, 30));
    button2->setFixedSize(QSize(80, 30));


    // 创建后两个按钮并使用水平布局
    QToolButton *button3 = new QToolButton(ui->tab);
    QToolButton *button4 = new QToolButton(ui->tab);
    QHBoxLayout *rightLayout = new QHBoxLayout;
    rightLayout->addWidget(button3);
    rightLayout->addWidget(button4);
    // 设置按钮的自适应大小
    button3->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    button4->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    // 创建一个竖线
    QFrame *line = new QFrame(ui->tab);
    line->setFrameShape(QFrame::VLine);
    line->setFrameShadow(QFrame::Sunken);

    // 创建一个水平布局并将所有布局和竖线添加进去
    QHBoxLayout *mainLayout = new QHBoxLayout(ui->tab);
    mainLayout->addLayout(leftLayout);
    mainLayout->addWidget(line);
    mainLayout->addLayout(rightLayout);
    mainLayout->setSpacing(10); // 设置间距为0
    mainLayout->addStretch();



    // // 创建一个竖线
    // QFrame *line2 = new QFrame();
    // line2->setFrameShape(QFrame::VLine);
    // line2->setFrameShadow(QFrame::Sunken);

    // QToolButton* tb0 = new QToolButton();


    // QHBoxLayout* qh = new QHBoxLayout(ui->tab_2);
    // qh->addWidget(tb0);
    // qh->addWidget(line);

    // QWidget* wid = new QWidget();
    // wid->setFixedSize(QSize(100, 80));
    // wid->setStyleSheet("background-color: gray;");
    // QHBoxLayout* qh2 = new QHBoxLayout(wid);
    // QToolButton* tb1 = new QToolButton();
    // QToolButton* tb2 = new QToolButton();
    // qh2->addWidget(tb1);
    // qh2->addWidget(tb2);
    // QMenu* menu=new QMenu(wid);
    // tb2->setMenu(menu);

    // QToolButton* tb3 = new QToolButton();
    // tb3->setFixedSize(QSize(10, wid->size().height()));

    // qh->addWidget(wid);
    // qh->addWidget(tb3);
    // qh->setSpacing(0); // 设置间距为0
    // qh->addStretch();

    // QAction* action1 = new QAction("1");
    // QAction* action2 = new QAction("2");
    // QAction* action3 = new QAction("3");
    // menu->addAction(action1);
    // menu->addAction(action2);
    // menu->addAction(action3);

    // QAction *menuAction = new QAction("Menu");
    // menuAction->setMenu(menu);
    // // 将动作添加到工具栏中
    // tb3->addAction(menuAction);

    // tb3->setMenu(menu);
    // tb3->setPopupMode(QToolButton::InstantPopup);

    // tb3->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);



    // 创建一个工具栏
    QToolBar *toolBar = new QToolBar("My Toolbar");
    QHBoxLayout* qh = new QHBoxLayout(ui->tab_2);
    qh->addWidget(toolBar);

    // 创建自定义菜单按钮
    CustomMenuButton *customMenuButton = new CustomMenuButton();
    toolBar->addWidget(customMenuButton);

}

MainWindow::~MainWindow()
{
    delete ui;
}
